package app.web.galgame.collects.yuinya;

import java.io.File;
import java.io.IOException;

import cn.lily.com.db.DBFactory;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.enviroment.Enviroment;

/**
 * 文件分析 - 补充密码信息
 * @author JiaJ
 *
 */
public class YuiNyaAnalyse {
	
	private String filePath = "H:/待处理/BT/BTX";
	
	public void analyse(){
		
		File folder = new File(this.filePath);
		
		File[] childFolders = folder.listFiles();
		for(File childFolder:childFolders){
			
			File[] childFiles = childFolder.listFiles();
			
			boolean isFile = false;
			for(File childFile:childFiles){
				String fileName = childFile.getName();			
				if(fileName.startsWith("yuinyan#") || fileName.startsWith("由依喵@")){
					isFile = true;
					
					int point = fileName.indexOf(".");
					String cutName = fileName.substring(0,point);
					
					DataTable dataTable = DBFactory.getThreadDB().executeQueryTable("select * from ${schema}.LEO_YUINYA_GAL_INFO where GAME_FILE_NAM like '%"+cutName+"%'");
					if(dataTable.getRecordCount()==1 && dataTable.next()){
						String pwd = dataTable.getString("GAME_FILE_PWD");
						
						System.out.println(childFolder.getPath().replaceAll("\\\\", "/")+"/"+pwd+".txt");
						
						File file = new File(childFolder.getPath().replaceAll("\\\\", "/")+"/"+pwd+".txt");
						try {
							file.createNewFile();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
					
					System.out.println(fileName);
					
					break;
				}
			}
			
		}
		
		System.out.println("文件分析结束！");
		
		
	}
	
	public static void main(String[] args) {
		
		Enviroment.createEnv();
		Enviroment.getEnv().getLogBean().beginLog();
		
		YuiNyaAnalyse analyse = new YuiNyaAnalyse();
		analyse.analyse();
		
		Enviroment.getEnv().getLogBean().endLog();
		
	}
	
}
